<!DOCTYPE html>
	<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>Document</title>
		<link rel="stylesheet" href="../layui/css/layui.css">
		<link rel="stylesheet" type="text/css" href="../css/i-party.css">
	</head>
	<body>
		<style type="text/css">
			#paymentpaw{
			width: 100%;
			position:fixed;
			width: 100%;
			height: 100%;
			display: none;
			z-index: 9999;
			background: rgba(0,0,0,0.5);
		}
		.enter{
			width: 100%;
			background:#FFFFFF;
			z-index: 102;
			position: fixed;
			bottom:0;
			z-index: 102;
			height: 50%;

		}
		.enter-close{
			width: 100%;
			padding: 1% 0;
		}
		.enter-close i{
			width: 1.5em;
			height: 1.5em;
			display: block;
			float: right;
			margin-right: 3%;
			margin-top: 3%;
			font-style: normal;
		}
		.enter-text{
			width: 100%;
			text-align: center;
			color: #8D8D8D;
			border-bottom:2px solid #F5F5F5 ;
			padding: 2% 0;
			margin-bottom: 4%;
		}
		.enter-input{
			text-align: center;

		}
		.enter-input input{
			width: 90%;
			border: 1px solid #CCCCCC;
			padding: 2% 0;
			text-align: center;
			font-size: 16px;
			display: inline-block;

		}
		.queding{
			padding: 3%;
		}
		.queding span{
			width: 100%;
			display: block;
			background: #57d5f3;
			border-radius: 15px;
			color: #fff;
			padding: 5px 0;
			text-align: center;
		}
		</style>
	<form action="">
		<div class="select">
			<div>
				<div class="center select-t">
					<p>发布约会</p>
					<img src="../img/cancel.png" class="close">
				</div>
				<div class="select-b">
					<p>"提示：发布约会即扣除<span>10</span>美金"</p>
					<div class="chengyijing">诚意金<span></span>美金</div>
					<div class="flex top-up-box">
						<p>支付金额：<span>￥510</span></p>
						<div class="top-up"><a href="recharge_usd.html">去充值</a></div>
					</div>
					<div class="sure center"><input type="button" id="submit" name="" value="确定发布"></div>
				</div>
			</div>
		</div>
		<div id="paymentpaw">
			<div class="enter">
				<div class="enter-close clearfix">
					<i>x</i>
				</div>
				<div class="enter-text">请输入支付密码</div>
				<div class="enter-input">
					<input type="password" name="pay" placeholder="输入支付密码">
				</div>

				<div class="queding"><span>确定发布</span></div>
			</div>
		</div>
		<header>
			<a href="javascript:history.back(-1)" class="back"><img src="../img/back.png" height="18px"></a>
			<div class="center title">发布约会</div>
		</header>
		<main>
			<div class="flex">
				<p>性别要求：</p>
			    <div class="female">
				    <input type="radio" value="女" id="female" name="ySex" />
				    <label for="female">女</label>
				</div>
				<div class="male">
				    <input type="radio" value="男" id="male" name="ySex" />
				    <label for="male">男</label>
				</div>
			</div>
			<div class="flex">
				<p>约会地点：</p>
				<input type="text" name="yAddress">
			</div>
			<div class="flex">
				<p>赴约时间：</p>
				<input type="text" name="yDate">
			</div>
			<div class="flex">
				<p>约会留言：</p>
				<textarea name="yContext"></textarea>
			</div>
		</main>
		<div class="parting-line"></div>
		<div class="money">
			<div class="flex">
				<!-- <div class="flex need">
					<p>需要人数:</p>
					<input type="text" name="yNum" value="1人" disabled>
				</div> -->
				<div class="flex need">
					<p>悬赏金:</p>
					<input type="text" name="yMeijin">
				</div>
				<!-- <div class="flex need">
					<p>诚意金:</p>
					<input type="text" name="">
				</div> -->
			</div>
			<div class="flex pay">
				<p>支付方式：</p>
				<div class="pay-r">
					<span class="pingtai"><input type="radio" class="pingtai" name="yPingtai" value="平台担保" checked>平台担保</span>
					<span class="xianxia"><input type="radio" name="yPingtai" value="线下支付">线下支付</span>
				</div>
			</div>
		</div>
		<div class="parting-line"></div>
		<div class="upload clearfix">
			<p>上传约会地点照片</p>
			<div class="add_photo">+<input type="file" name="mfile" id="file" value=""></div>
		</div>
		<div class="parting-line"></div>
		<div class="fabu center">发布约会</div>

	</form>
		<script src="../js/jquery-3.3.1.js"></script>
		<script src="../layui/layui.all.js"></script>
		<script src="../js/i-party.js"></script>
	</body>
</html>
<script>
	var arr=[];
	$("#file").change(function() {
		//获取图片信息
		var fileLise = $(this)[0].files;
		var fileLength = fileLise.length;
		//然后循环 生成html 插入页面上 最后就赋值给img
		for (var i = 0; i < fileLength; i++) {
			var imgDiv = '<div class="imgDiv" style="width: 80px;height: 80px;display: inline-block;border: none;margin: 15px;"><img style="width: 100%;height: 100%" id="img' + fileLise[i].name + '"></div>';
			$(".upload").append(imgDiv);
			var imgName = document.getElementById("img" + fileLise[i].name);
			// var imgurl=window.URL.createObjectURL(fileLise[i]);
			if (fileLise && fileLise[i]) {
				var file = new FileReader();
				file.readAsDataURL(fileLise[i]);
				file.onload = function() {
					console.log(this);
					imgName.src = this.result;
				}
				arr.push($(this)[i].files[0]);
			}

			if(arr.length>=3){
				$('.add_photo').hide();
			}else {
				$('.add_photo').show();
			}
		}
	});
	$(document).on("click", ".imgDiv", function() {
		var index=$(this).index();
		arr.splice(index-2,1);
		$(this).remove();
		if(arr.length<3){
			$('.add_photo').show();
		}
	});
	
	$.get('/meiyou/getFaBujin',function(data){
			console.log(data.num);
			$('.select-b>p span').text(data.num);
			

	});
 

		$.get('/meiyou/getChenYiJin',function(data){
			console.log(data.chenyijin);
			$('.chengyijing').show();
			$('.chengyijing span').text(data.chenyijin);	
		});
		$(document).on('click','.pingtai',function(){
			$.get('/meiyou/getChenYiJin',function(data){
			console.log(data.chenyijin);
			$('.chengyijing').show();
			$('.chengyijing span').text(data.chenyijin);	
		});
	});
		$(document).on('click','.xianxia',function(){
			$('.chengyijing').hide();
			$('.chengyijing span').text(0);
	});
			
$('.fabu').click(function(){
		var chengyijing=parseInt($('.chengyijing span').text());
		var fbprice=parseInt($('.select-b>p span').text());
        var xsprice=parseInt($('input[name="yMeijin"]').val());
        var price=fbprice+xsprice+chengyijing;
        $('.top-up-box>p span').text('￥'+price);
	});
	
	$('.enter-close').click(function(){
		$('#paymentpaw').hide();
	});
	$('#submit').click(function () {
		$('#paymentpaw').show();
		
	});
	$('.queding').click(function () {
		var formData= new FormData();
		var chengyijing=parseInt($('.chengyijing span').text());
		var fbprice=parseInt($('.select-b>p span').text());
		// var xsprice=parseInt($('input[name="yMeijin"]').val());
		var ySex=$('input[name="ySex"]:checked').val();
		var yAddress=$('input[name="yAddress"]').val();
		var yDate=$('input[name="yDate"]').val();
		var yContext=$('textarea[name="yContext"]').val();
		var yPingtai=$('input[name="yPingtai"]:checked').val();
		// var yUCount=$('input[name="yUCount"]').val();
		var yMeijin=parseInt(fbprice+chengyijing);
		var pay=$('input[name="pay"]').val();
		for(var i=0;i<arr.length;i++){
			formData.append('mfile',arr[i]);
		}
		
		formData.append('ySex',ySex);
		formData.append('yAddress',yAddress);
		formData.append('yDate',yDate);
		formData.append('yContext',yContext);
		formData.append('yPingtai',yPingtai);
		/*formData.append('yUCount',yUCount);*/
		formData.append('yMeijin',yMeijin);
		formData.append('pay',pay);
		$.ajax({
			url: "/meiyou/fabuYuehui",
			data:formData,
			type: "Post",
            cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (data) {
            	if(data.code==100){
            		layer.msg(data.msg,{icon:6,time:1000},function(){
	        		window.location.reload();
	        	})
            	}else{
            		layer.msg(data.msg,{icon:5,time:1000})
            	}
            	
            	console.log(data)
            }
        })
	});
</script>
